package com.tzbank.back.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tzbank.back.dao.LotteryDeployMapper;
import com.tzbank.back.service.LotteryDeployService;
import com.tzbank.entity.backstage.LotteryDeploy;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

/**
 * 抽奖管理配置
 * @author 蔡宇钿
 *2018年6月1日
 */
@Service(value="lotteryDeployService")
public class LotteryDeployServiceImpl implements LotteryDeployService {

	@Autowired
	private LotteryDeployMapper lotteryDeployMapper;
	
	@Transactional
	@Override
	public Map<String, Object> deleteBylottauto(LotteryDeploy lotteryDeploy) throws Exception{
		// 通过逻辑方式实现删除
		lotteryDeploy.setStatus("0");
		lotteryDeploy.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.lotteryDeployMapper.deleteBylottauto(lotteryDeploy);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Override
	public Map<String, Object> getlistBylotteryactivname(String activename) throws Exception{
		// 按照activename查询
		LotteryDeploy lotteryDeploy = this.lotteryDeployMapper.getlistBylotteryactivname(activename);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), lotteryDeploy);
	}

	@Override
	public Map<String, Object> getlistLottery() throws Exception{
		// 查询全部
		List<LotteryDeploy> lotteryDeploy = this.lotteryDeployMapper.getlistLottery();
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), lotteryDeploy);
	}

	@Transactional
	@Override
	public Map<String, Object> addLottery(LotteryDeploy lotteryDeploy) throws Exception {
		// 增加配置
		lotteryDeploy.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		lotteryDeploy.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		lotteryDeployMapper.addLottery(lotteryDeploy);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Transactional
	@Override
	public Map<String, Object> modifyBylotteryautoId(LotteryDeploy lotteryDeploy) throws Exception{
		// 更新配置
		lotteryDeploy.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.lotteryDeployMapper.modifyBylotteryautoId(lotteryDeploy);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

}
